<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
          "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>QUnit for KEYUTIL private key reader 'keyutil.js'</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>

<!-- script type="text/javascript" src="qunit.js" /script -->
<!-- link rel="stylesheet" href="qunit.css" type="text/css" media="screen" -->
<script src="http://code.jquery.com/qunit/qunit-1.11.0.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.11.0.css" type="text/css" media="screen"/>

<script src="../ext/jsbn.js"></script>
<script src="../ext/jsbn2.js"></script>
<script src="../ext/prng4.js"></script>
<script src="../ext/rng.js"></script>
<script src="../ext/base64.js"></script>
<script src="../ext/rsa.js"></script>
<script src="../ext/rsa2.js"></script>

<script src="../src/asn1hex-1.1.js"></script>
<script src="../src/rsapem-1.1.js"></script>
<script src="../src/rsasign-1.2.js"></script>

<script src="../ext/cj/cryptojs-312-core-fix.js"></script>
<script src="../ext/cj/x64-core.js"></script>
<script src="../ext/cj/cipher-core_min.js"></script>
<script src="../ext/cj/aes_min.js"></script>
<script src="../ext/cj/tripledes_min.js"></script>
<script src="../ext/cj/enc-base64_min.js"></script>
<script src="../ext/cj/md5_min.js"></script>
<script src="../ext/cj/sha1_min.js"></script>
<script src="../ext/cj/sha256_min.js"></script>
<script src="../ext/cj/sha224_min.js"></script>
<script src="../ext/cj/sha512_min.js"></script>
<script src="../ext/cj/sha384_min.js"></script>
<script src="../ext/cj/ripemd160_min.js"></script>
<script src="../ext/cj/hmac_min.js"></script>
<script src="../ext/cj/pbkdf2_min.js"></script>

<script src="../ext/yahoo.js"></script>
<script src="../ext/jsbn.js"></script>
<script src="../ext/jsbn2.js"></script>
<script src="../ext/prng4.js"></script>
<script src="../ext/rng.js"></script>
<script src="../ext/ec.js"></script>
<script src="../ext/ec-patch.js"></script>

<script src="../src/base64x-1.1.js"></script>
<script src="../src/asn1-1.0.js"></script>
<script src="../src/keyutil-1.0.js"></script>
<script src="../src/dsa-2.0.js"></script>
<script src="../src/x509-1.1.js"></script>
<script src="../src/crypto-1.1.js"></script>
<script src="../src/ecdsa-modified-1.0.js"></script>
<script src="../src/ecparam-1.0.js"></script>

<script type="text/javascript">
<!--
$(document).ready(function(){

// key _work_dsa/d1
var p = new BigInteger("9ed327a12407c8d2dc9a6b9359fbc48f2a317504f33b48661c4b03778f55b818af219285bbcdfa60f63f96f5c3c06738d72432a36f46d6490a0fe70238517671e7abdb430c4ffb74a17fb6d0ceceee28fddb49273bcd165a520e4a9717b4d27ef06f3417df6a9ea2da35058f119ae76ac8095a2c45ee576c3dfe8253f3449a4f", 16);
var q = new BigInteger("832124c3188298f8d6dd1ad84121c2ef33a5d52b", 16);
var g = new BigInteger("711ac4053baf502aa0a09abcb7af72885495e1efb0de129d93c7bb16f0e4b80a1a10d0409ed52bcd0df0b5511f6e08f74715517e9406edd45d78f0ef15d92b27ef398ea7bf9365fa13591322149fa84635187da277f15cbc8c9a28423feb233221e5d1ad36d926d2e1e0c770f34dc04a616f55685222a9b1cf4f8ecf87c19b7e", 16);
var y = new BigInteger("8cafd9654ce51818e154613bd0b14ee974fbdffc5a19802c4301302bc854d5e17daf0d6745a4aaa8e46ff96b57c89371fa72cca12a2248821645d1ff75869a2549ad7fd110ceefea5616d00be5941036e1a2d87bbcf0bfbe6c3b1e18ba0d3b3af6d34bacf613270a0b5f67c78668e4ba5b3ec0aa28e762ea1f9f2e0167e0523b", 16);
var x = new BigInteger("73b3538660ceac98a3bf48e53f88b4e124657c21", 16);

// _work_dsa/d1.pub.p8.pem DSA 1024bit
var d1PubP8PEM = "" +
"-----BEGIN PUBLIC KEY-----\n" +
"MIIBtzCCASsGByqGSM44BAEwggEeAoGBAJ7TJ6EkB8jS3Jprk1n7xI8qMXUE8ztI\n" +
"ZhxLA3ePVbgYryGShbvN+mD2P5b1w8BnONckMqNvRtZJCg/nAjhRd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bZJtLh4Mdw803ASmFvVWhSIqmxz0+O\n" +
"z4fBm34CgYEAjK/ZZUzlGBjhVGE70LFO6XT73/xaGYAsQwEwK8hU1eF9rw1nRaSq\n" +
"qORv+WtXyJNx+nLMoSoiSIIWRdH/dYaaJUmtf9EQzu/qVhbQC+WUEDbhoth7vPC/\n" +
"vmw7Hhi6DTs69tNLrPYTJwoLX2fHhmjkuls+wKoo52LqH58uAWfgUjsCFHOzU4Zg\n" +
"zqyYo79I5T+ItOEkZXwh\n" +
"-----END DSA PRIVATE KEY-----\n";

// _work_dsa/d1.prv.p5e.pem DSA 1024bit
var d1PrvP5EPEM = "" +
"-----BEGIN DSA PRIVATE KEY-----\n" +
"Proc-Type: 4,ENCRYPTED\n" +
"DEK-Info: DES-EDE3-CBC,0A4241238121CC53\n" +
"\n" +
"SREBGTs1GdPEyT0O4MQIPfZZ59Wj8dcvqyEv+IlHzztZbqUiBfGYidu5ybhhaq8W\n" +
"FvDLUTyUPhWqjnTPI0P73t/nMFhZEEB/PWP4SCCXcsd+8ygIEVQfXl9CcFfFxsiP\n" +
"UhRBaZrU/yQ/IynKSboA/RfysHyfJTn3GcJLmMDhs7x4yZr+E8FIfk15qXCkzEsH\n" +
"yFkhDi0D23RfttXie5HiQE0e2XsB127aCkYfQ5nMesrGTVtQb+8cuodtejmGtFtT\n" +
"kslgs45yRNUznxxMi/61sm6pkH///ow0w5DN74UQsqpJj4CYhhNQY4r/QnK8SvlL\n" +
"+KFXazkFwWNZbXiyxF7zdaCsb5bglvfmJspSDGUIcxPzwMG1GQBA3IqOegjmgU/5\n" +
"LMElak/HMFFjT+jUUvxVSJIWK7f4+lWypwPkmmZib9dx8XHPpUr/vXBwPLE40fRG\n" +
"9enP7lSZRWjmW9alWIn6dpjG5HsQwH4eMxdD1fqLR7BR+nx+z47wqmAXPIzOL7PW\n" +
"N4nVxc1+juzITbT6HZB5gkHJG/5l/YFDsACK8aLHp+lgM/Onyg3cMDKSbaXERPZb\n" +
"q0MrwzdrLyCc6x9HYz2QDA==\n" +
"-----END DSA PRIVATE KEY-----\n";
var d1PrvP5EPass = "passwd";

var D1PRVP5HEX = "308201bb020100028181009ed327a12407c8d2dc9a6b9359fbc48f2a317504f33b48661c4b03778f55b818af219285bbcdfa60f63f96f5c3c06738d72432a36f46d6490a0fe70238517671e7abdb430c4ffb74a17fb6d0ceceee28fddb49273bcd165a520e4a9717b4d27ef06f3417df6a9ea2da35058f119ae76ac8095a2c45ee576c3dfe8253f3449a4f021500832124c3188298f8d6dd1ad84121c2ef33a5d52b028180711ac4053baf502aa0a09abcb7af72885495e1efb0de129d93c7bb16f0e4b80a1a10d0409ed52bcd0df0b5511f6e08f74715517e9406edd45d78f0ef15d92b27ef398ea7bf9365fa13591322149fa84635187da277f15cbc8c9a28423feb233221e5d1ad36d926d2e1e0c770f34dc04a616f55685222a9b1cf4f8ecf87c19b7e028181008cafd9654ce51818e154613bd0b14ee974fbdffc5a19802c4301302bc854d5e17daf0d6745a4aaa8e46ff96b57c89371fa72cca12a2248821645d1ff75869a2549ad7fd110ceefea5616d00be5941036e1a2d87bbcf0bfbe6c3b1e18ba0d3b3af6d34bacf613270a0b5f67c78668e4ba5b3ec0aa28e762ea1f9f2e0167e0523b021473b3538660ceac98a3bf48e53f88b4e124657c21";

var D1PRVP8HEX = "3082014a0201003082012b06072a8648ce3804013082011e028181009ed327a12407c8d2dc9a6b9359fbc48f2a317504f33b48661c4b03778f55b818af219285bbcdfa60f63f96f5c3c06738d72432a36f46d6490a0fe70238517671e7abdb430c4ffb74a17fb6d0ceceee28fddb49273bcd165a520e4a9717b4d27ef06f3417df6a9ea2da35058f119ae76ac8095a2c45ee576c3dfe8253f3449a4f021500832124c3188298f8d6dd1ad84121c2ef33a5d52b028180711ac4053baf502aa0a09abcb7af72885495e1efb0de129d93c7bb16f0e4b80a1a10d0409ed52bcd0df0b5511f6e08f74715517e9406edd45d78f0ef15d92b27ef398ea7bf9365fa13591322149fa84635187da277f15cbc8c9a28423feb233221e5d1ad36d926d2e1e0c770f34dc04a616f55685222a9b1cf4f8ecf87c19b7e0416021473b3538660ceac98a3bf48e53f88b4e124657c21"; // d1.prv.p8p.der

var D1PUBP8HEX = "308201b73082012b06072a8648ce3804013082011e028181009ed327a12407c8d2dc9a6b9359fbc48f2a317504f33b48661c4b03778f55b818af219285bbcdfa60f63f96f5c3c06738d72432a36f46d6490a0fe70238517671e7abdb430c4ffb74a17fb6d0ceceee28fddb49273bcd165a520e4a9717b4d27ef06f3417df6a9ea2da35058f119ae76ac8095a2c45ee576c3dfe8253f3449a4f021500832124c3188298f8d6dd1ad84121c2ef33a5d52b028180711ac4053baf502aa0a09abcb7af72885495e1efb0de129d93c7bb16f0e4b80a1a10d0409ed52bcd0df0b5511f6e08f74715517e9406edd45d78f0ef15d92b27ef398ea7bf9365fa13591322149fa84635187da277f15cbc8c9a28423feb233221e5d1ad36d926d2e1e0c770f34dc04a616f55685222a9b1cf4f8ecf87c19b7e03818500028181008cafd9654ce51818e154613bd0b14ee974fbdffc5a19802c4301302bc854d5e17daf0d6745a4aaa8e46ff96b57c89371fa72cca12a2248821645d1ff75869a2549ad7fd110ceefea5616d00be5941036e1a2d87bbcf0bfbe6c3b1e18ba0d3b3af6d34bacf613270a0b5f67c78668e4ba5b3ec0aa28e762ea1f9f2e0167e0523b"; // d1.pub.p8.der

var D1CERTHEX = "308202c430820282a003020102020900fd8cc68e37232612300b0609608648016503040302301a310b3009060355040613025553310b3009060355040a0c024431301e170d3133313030323135303434345a170d3233303933303135303434345a301a310b3009060355040613025553310b3009060355040a0c024431308201b73082012b06072a8648ce3804013082011e028181009ed327a12407c8d2dc9a6b9359fbc48f2a317504f33b48661c4b03778f55b818af219285bbcdfa60f63f96f5c3c06738d72432a36f46d6490a0fe70238517671e7abdb430c4ffb74a17fb6d0ceceee28fddb49273bcd165a520e4a9717b4d27ef06f3417df6a9ea2da35058f119ae76ac8095a2c45ee576c3dfe8253f3449a4f021500832124c3188298f8d6dd1ad84121c2ef33a5d52b028180711ac4053baf502aa0a09abcb7af72885495e1efb0de129d93c7bb16f0e4b80a1a10d0409ed52bcd0df0b5511f6e08f74715517e9406edd45d78f0ef15d92b27ef398ea7bf9365fa13591322149fa84635187da277f15cbc8c9a28423feb233221e5d1ad36d926d2e1e0c770f34dc04a616f55685222a9b1cf4f8ecf87c19b7e03818500028181008cafd9654ce51818e154613bd0b14ee974fbdffc5a19802c4301302bc854d5e17daf0d6745a4aaa8e46ff96b57c89371fa72cca12a2248821645d1ff75869a2549ad7fd110ceefea5616d00be5941036e1a2d87bbcf0bfbe6c3b1e18ba0d3b3af6d34bacf613270a0b5f67c78668e4ba5b3ec0aa28e762ea1f9f2e0167e0523ba350304e301d0603551d0e04160414b0a8b5b2d1e7a5291a742ea6ee0f1cf0d1d45b4a301f0603551d23041830168014b0a8b5b2d1e7a5291a742ea6ee0f1cf0d1d45b4a300c0603551d13040530030101ff300b0609608648016503040302032f00302c02147ff6dde28ad40095342cdbf2e5e2621ed30db85d021422c71bc20564bd68beecf2f631cd0e3f3c649430"; // d1.self.cer.der

// ======= TEST ============================================================================

test("KEYUTIL.getKey d1(DSA 1024bit)", function() {
var key = KEYUTIL.getKey(d1PubP8PEM);
ok(key instanceof KJUR.crypto.DSA, "isDSA");
equal(p.compareTo(key.p), 0, "p");
equal(q.compareTo(key.q), 0, "q");
equal(g.compareTo(key.g), 0, "g");
equal(y.compareTo(key.y), 0, "y");
});

test("X509.getPublicKeyFromCertPEM d1(DSA 1024bit)", function() {
var key = X509.getPublicKeyFromCertPEM(d1CerPEM);
expect(5);
ok(key instanceof KJUR.crypto.DSA, "isDSA");
equal(p.compareTo(key.p), 0, "p");
equal(q.compareTo(key.q), 0, "q");
equal(g.compareTo(key.g), 0, "g");
equal(y.compareTo(key.y), 0, "y");
});

test("KEYUTIL.getKey(d1.prv.p5p.pem(DSA 1024bit))", function() {
var key = KEYUTIL.getKey(d1PrvP5PPEM);
expect(7);
ok(key instanceof KJUR.crypto.DSA, "isDSA");
equal(p.compareTo(key.p), 0, "p");
equal(q.compareTo(key.q), 0, "q");
equal(g.compareTo(key.g), 0, "g");
equal(y.compareTo(key.y), 0, "y");
equal(x.toString(16), key.x.toString(16), "x_s");
equal(x.compareTo(key.x), 0, "x");
});

test("KEYUTIL.getKey(d1.prv.p5e.pem(DSA 1024bit))", function() {
var key = KEYUTIL.getKey(d1PrvP5EPEM, d1PrvP5EPass);
expect(7);
ok(key instanceof KJUR.crypto.DSA, "isDSA");
equal(p.compareTo(key.p), 0, "p");
equal(q.compareTo(key.q), 0, "q");
equal(g.compareTo(key.g), 0, "g");
equal(y.compareTo(key.y), 0, "y");
equal(x.toString(16), key.x.toString(16), "x_s");
equal(x.compareTo(key.x), 0, "x");
});

test("KEYUTIL.getKeyFromPlainPrivatePKCS8Hex(D1PRVP8HEX) d1.prv.p8p.der", function() {
  var key = KEYUTIL.getKeyFromPlainPrivatePKCS8Hex(D1PRVP8HEX);
  equal(key.isPublic, false, "isPublic");
  equal(key.isPrivate, true, "isPrivate");
  equal(p.compareTo(key.p), 0, "P");
  equal(q.compareTo(key.q), 0, "Q");
  equal(g.compareTo(key.g), 0, "G");
  equal(key.y, null, "Y");
  equal(x.compareTo(key.x), 0, "X");
});

test("KEYUTIL.getKey(D1PRVP5HEX, null, pkcs5prv) d1.prv.p5p.der", function() {
  var key = KEYUTIL.getKey(D1PRVP5HEX, null, "pkcs5prv");
  equal(key.isPublic, false, "isPublic");
  equal(key.isPrivate, true, "isPrivate");
  equal(p.compareTo(key.p), 0, "P");
  equal(q.compareTo(key.q), 0, "Q");
  equal(g.compareTo(key.g), 0, "G");
  equal(y.compareTo(key.y), 0, "Y not null");
  equal(x.compareTo(key.x), 0, "X");
});

test("KEYUTIL.getKey(D1PRVP8HEX, null, pkcs8prv) d1.prv.p8p.der", function() {
  var key = KEYUTIL.getKey(D1PRVP8HEX, null, "pkcs8prv");
  equal(key.isPublic, false, "isPublic");
  equal(key.isPrivate, true, "isPrivate");
  equal(p.compareTo(key.p), 0, "P");
  equal(q.compareTo(key.q), 0, "Q");
  equal(g.compareTo(key.g), 0, "G");
  equal(key.y, null, "Y null");
  equal(x.compareTo(key.x), 0, "X");
});

test("KEYUTIL.getKey(D1PUBP8HEX, null, pkcs8pub) d1.pub.p8.der", function() {
  var key = KEYUTIL.getKey(D1PUBP8HEX, null, "pkcs8pub");
  equal(key.isPublic, true, "isPublic");
  equal(key.isPrivate, false, "isPrivate");
  equal(p.compareTo(key.p), 0, "P");
  equal(q.compareTo(key.q), 0, "Q");
  equal(g.compareTo(key.g), 0, "G");
  equal(y.compareTo(key.y), 0, "Y not null");
});

test("KEYUTIL.getKey(D1CERTHEX, null, x509pub) d1.self.cer.der", function() {
  var key = KEYUTIL.getKey(D1CERTHEX, null, "x509pub");
  equal(key.isPublic, true, "isPublic");
  equal(key.isPrivate, false, "isPrivate");
  equal(p.compareTo(key.p), 0, "P");
  equal(q.compareTo(key.q), 0, "Q");
  equal(g.compareTo(key.g), 0, "G");
  equal(y.compareTo(key.y), 0, "Y not null");
});

});
-->
</script>
  
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">test markup</div>
<a href="../">TOP</a> | 
<a href="index.html">TEST INDEX</a> | 
<a href="qunit-do-keyutil.html">keyutil</a> | 
<a href="qunit-do-keyutil-rsa.html">keyutil-rsa</a> | 
<a href="qunit-do-keyutil-dsa.html">keyutil-dsa</a> | 
<a href="qunit-do-keyutil-ec.html">keyutil-ec</a> | 
<a href="qunit-do-keyutil-eprv.html">keyutil-eprv</a> | 
<a href="qunit-do-keyutil-pub.html">keyutil-pub</a> | 
</body>
</html>

